package com.yeshine.opendata.controller.front;

import com.yeshine.opendata.core.ControllerBase;
import com.yeshine.opendata.entity.User;
import com.yeshine.opendata.utils.Result;
import org.springframework.stereotype.Controller;

/**
 * Created by taohj on 2014/7/7.
 */

@Controller

public abstract class AbstractFrontControllerBase extends ControllerBase {

    public  static  final  String FRONT="/front/";

    public String setRequestForwordAttr(String title, String message, String url) {
        setSessionAttr("title", title);
        setSessionAttr("message", message);
        setSessionAttr("url", url);
        return "redirect:/front/successforword";
    }




    public String setMessage(String title,String message){
        setSessionAttr("title", title);
        setSessionAttr("message", message);
        return "redirect:"+getPagePath("message");
    }


    public String setMessage(Result result){
        setSessionAttr("title", "操作失败");
        setSessionAttr("message",result.getMessage());
        return "redirect:"+getPagePath("message");
    }


    public String setMessage(){
        setSessionAttr("title", "操作失败");
        setSessionAttr("message","请联系管理员");
        return "redirect:"+getPagePath("message");
    }



    public static User getCurrentUser(){
        return  (User)(getSession().getAttribute("user"));
    }

    public void setCurrentUser(User user){
        getSession().setAttribute("user",user);
    }



    public  String getPagePath(String path){
        return  FRONT+path;
    }


    public  void setBasePath(){
        setRequestAttr("basePath",getBasePath());
    }



    public  String getFrontRedirect(String path){

        return "redirect:/front/"+path;
    }


    


}
